const express = require('express');
const path = require('path');
const user = require('./router');

const app = express();

//配置body
app.use(express.urlencoded({extends: false}));
app.use(express.json());

app.use(express.static(path.join(__dirname, 'public')));

//设置允许跨域访问该服务
app.all('*',function(req,res,next) {
    res.header('Access-Control-Allow-Origin','*');
    res.header('Access-Control-Allow-Methods','PUT,GET,POST,DELETE,OPTTONS');
    res.header('Access-Control-Allow-Headers','X-Requested-With');
    res.header('Access-Control-Allow-Headers','Content-Type');
    next();
});

//配置路由
app.use(user);

app.listen(3000,() => {
    console.log('服务器连接成功');
})